#include "LineEntity.h"
#include <QPainter>

LineEntity::LineEntity(void)
{
}


LineEntity::~LineEntity(void)
{
}

TGS::GeoMath::Envelope LineEntity::getEnvelope() const
{
	if(!isSpaceModel()) return Envelope();

	Envelope envolope;
	envolope.expandToInclude(_startPoint);
	envolope.expandToInclude(_endPoint);

	return envolope;
}

void LineEntity::render( RenderContext* renderContext )
{
	renderContext->painter()->save();

	QPoint startPoint = renderContext->mapToPixel().mapToScreen(_startPoint);
	QPoint endPoint = renderContext->mapToPixel().mapToScreen(_endPoint);

	QPen pen(QBrush(getColor()), getWidth());
	renderContext->painter()->setPen(pen);
	renderContext->painter()->drawLine(startPoint, endPoint);

	renderContext->painter()->restore();
}

void LineEntity::traslate( const Point& point )
{
	_startPoint.setX(_startPoint.getX() + point.getX());
	_startPoint.setY(_startPoint.getY() + point.getY());

	_endPoint.setX(_endPoint.getX() + point.getX());
	_endPoint.setY(_endPoint.getY() + point.getY());
}
